<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
<head>
    <title></title>
    <link href="<s:url value='/common/lib/ligerUI/skins/Aqua/css/ligerui-all.css'/>" rel="stylesheet" type="text/css" />
	<script src="<s:url value='/common/lib/jquery/jquery-1.3.2.min.js'/>" type="text/javascript"></script>
	<script src="<s:url value='/common/lib/ligerUI/js/core/base.js'/>" type="text/javascript"></script>
	<script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerGrid.js'/>" type="text/javascript"></script>
	<script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerDialog.js'/>" type="text/javascript"></script>
    <style type="text/css">
		body { 
			font-family: "微软雅黑", "宋体", Arial, sans-serif; 
			font-size: 12px; 
		}
		.file-box{position:relative;width:500px;padding: 5px;} 
		.txt{height:22px; border:1px solid #cdcdcd; width:180px;} 
		.btn{background-color:#FFF; border:1px solid #CDCDCD;height:24px; width:120px;} 
		.file{position:absolute; right:205px; top:0; height:24px; filter:alpha(opacity:0); opacity:0;}
		.errors {
			background-color:#FFCCCC;
			border:1px solid #CC0000;
			width:800px;
			margin-bottom:8px;
		}
		.errors li{ 
			list-style: none; 
		}
	</style>
    <script type="text/javascript">
    	var manager = null;
        $(function () {
        	var y = $("#year").val();
        	var q = $("#quarter").val();
        	$("#uploadFile").hide();
        	if(y != "" && q != 0) {
        		$("#years").val(y);
        		$("input[type=radio][value="+q+"]").attr("checked",'checked');
        	}
        	
        	var r = $("#recordsJOSNStr").val();
        	if(r) {
        		manager = $("#maingrid").ligerGrid({
	                columns: [
	                {display:'盘查人员姓名', name:'userName', width:120},
	                {display:'完成度', name:'percentage', width:80},
					{display:'已盘查经销商列表', width:180, isSort:false,
						render:function () {
							return "<a href='javascript:toFinishedWork()'>查看</a> ";
						}},
					{display:'计划盘查经销商列表', width:180, isSort:false,
							render:function () {
								return "<a href='javascript:toPlanWork()'>查看</a> ";
							}}],
	                enabledEdit:false,
					clickToEdit:false,
					width: '100%',
					height: 655,
					pageSize:30,
	                data:eval('(' + r + ')')
	            });
        	}
        });
        
        function toFinishedWork() {
        	var row = manager.getSelectedRow();
        	var y = $("#years").val();
        	var q = $("input[name='quarters']:checked").val();
        	$.ligerDialog.open({title:'计划盘查经销商列表', width:450, height:600, 
        		url:"<s:url value='/record/toFinishedWork.action'/>" + "?year=" + y + "&quarter=" + q + "&userName=" + row.userName, 
        		buttons: [{text:'确定', onclick:closeDialog}]});
        }
        
		function toPlanWork() {
			var row = manager.getSelectedRow();
        	var y = $("#years").val();
        	var q = $("input[name='quarters']:checked").val();
        	var s = $("#suffix").val();
        	$.ligerDialog.open({title:'计划盘查经销商列表', width:450, height:600, 
        		url:"<s:url value='/record/toPlanWork.action'/>" + "?year=" + y + "&quarter=" + q + "&suffix=" + s + "&userName=" + row.userName, 
        		buttons: [{text:'确定', onclick:closeDialog}]});
        }
		
		function closeDialog(item, dialog) {
	            dialog.close();
		} 
        
        function doStatistic() {
        	var y = $("#years").val();
        	var q = $("input[name='quarters']:checked").val();
        	$("#doStatisticBtn").attr("disabled","disabled");
        	$.post("<s:url value='/record/checkWorkloadFile.action'/>",{year:y,quarter:q}, function(data) {
        		var r = data.split(":");
				if(r[0] == 0) {
					$("#workloadFileName").val(r[1].replace(/\r/g, "").replace(/\n/g, ""));
					$("#doWorkloadStatisticForm").submit();
				} else {
					$("#doStatisticBtn").hide();
					$.ligerDialog.alert(r[1], "错误", "error");
					$("#uploadFile").show();
				}
			});
        }
        
        function uploadFile() {
        	var fileName = $("#originalFile").val();
    		if(fileName == "") {
    			$.ligerDialog.alert("请选择盘库行程排期表", "错误", "error");
    			return false;
    		}
    		$.ligerDialog.confirm('请确定确定盘库行程排期表格式是否正确', function (yes) {
    			if(yes) {
    				var suffix = fileName.substr(fileName.lastIndexOf('.') + 1).toLowerCase();
    				if(suffix != "xls" && suffix != "xlsx") {
    					$.ligerDialog.alert("盘库行程排期表不正确，请上传excel文件", errorMsgTitle, "error");
    					return false;
    				}
    				$("input[type='button']").attr("disabled","disabled");
    				$("input[type='text']").attr("disabled","disabled");
    				$("#year").val($("#years").val());
    				$("#quarter").val($("input[name='quarters']:checked").val());
    				$("#suffix").val(suffix);
    				$("#uploadFileForm").submit();
    				return true;
    			} else {
    				$("#textfield").val("");
    			}
    		});
    		return false;
        }
    </script>
</head>
<body style="padding:10px">
	<s:hidden name="recordsJOSNStr"/>
	<h3>执行员工作量统计</h3>
	<s:if test="hasActionErrors()">
   			<div id="errorMsg" class="errors">
      			<s:actionerror/>
   			</div>
    </s:if>
	<div style="width:100%; height:auto;">
		<div id="yearBox" style="margin: 5px;">
			<label id="yearLabel" for="year">请选年份：</label>
			<select id="years">
				<option value="2010">2010</option>
				<option value="2011">2011</option>
				<option value="2012">2012</option>
				<option value="2013" selected="selected">2013</option>
				<option value="2014">2014</option>
				<option value="2015">2015</option>
				<option value="2016">2016</option>
				<option value="2017">2017</option>
				<option value="2018">2018</option>
				<option value="2019">2019</option>
				<option value="2020">2020</option>
				<option value="2021">2021</option>
				<option value="2022">2022</option>
				<option value="2023">2023</option>
				<option value="2024">2024</option>
				<option value="2025">2025</option>
			</select>
		</div>
		<div id="quarterBox" style="margin: 5px;">
			<label id="quarterLabel" for="quarter">请选季度：</label>
			<input id="quarters" type="radio" value="1" name="quarters" checked="checked">一季度</input>
			<input type="radio" value="2" name="quarters">二季度</input>
			<input type="radio" value="3" name="quarters">三季度</input>
			<input type="radio" value="4" name="quarters">四季度</input>
		</div>
		<div id="inputBox" style="margin: 5px;">
			<input id="doStatisticBtn" type="button" onclick="doStatistic()" class="btn" value="统计"></input>
		</div>
		<div id="uploadFile" class="file-box"> 
			<form id="uploadFileForm" action="<s:url value='/record/uploadWorkloadFile.action'/>" method="post" enctype="multipart/form-data">
				<s:hidden name="year"/>
				<s:hidden name="quarter"/>
				<s:hidden name="suffix"/>
				<input type='text' id='textfield' name='textfield' class='txt' onclick="document.getElementById('originalFile').click()"/> 
				<input type='button' class='btn' value='选择排期表...' onclick="document.getElementById('originalFile').click()"/> 
				<input type="file"  name="originalFile" class="file" id="originalFile" size="28" onchange="document.getElementById('textfield').value=this.value" /> 
				<input type="button" class="btn" value="上传" onclick="uploadFile()"/> 
			</form> 
		</div>
		
		<div class="l-clear"></div>
	
    	<div id="maingrid" style="margin-top:20px"></div>
    
   		<div style="display:none;"></div>
   		
   		<form id="doWorkloadStatisticForm" action="<s:url value='/record/doWorkloadStatistic.action'/>" method="post">
   			<s:hidden name="workloadFileName"/>
   		</form>
	</div>
</body>
</html>